#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

class ShorterString {
    public:
        bool operator()(const string& s1, const string& s2) const
            { return s1.size() < s2.size(); }
};

class SizeComp {
    public:
        SizeComp(size_t n): sz(n) {}    // 该形参对应捕获的变量
        // 该调用运算符的返回类型、形参和函数体都与 lambda 一致
        bool operator()(const string& s) const
            { return s.size() >= sz; };
    private:
        size_t sz;                      // 该数据成员对应通过值捕获的变量
};

int main()
{
    vector<string> words{"bbb", "cccc", "aa"};
    // stable_sort(words.begin(), words.end(), 
    //             [] (const string &a, const string &b)
    //                 { return a.size() < b.size(); });
    stable_sort(words.begin(), words.end(), ShorterString());

    // 获得第一个指向满足条件元素的迭代器
    size_t sz = 4;
    // auto wc = find_if(words.begin(), words.end(),
    //             [sz](const string &a)
    //                 { return a.size() >= sz; });
    auto wc = find_if(words.begin(), words.end(), SizeComp(sz));
}